<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.controller');

class OwnserviceControllerReport extends OwnserviceController
{
	/**
	 * Controller constructor
	 *
	 * @since 1.0
	 */
	function __construct() {
		parent::__construct();
	}

	/**
	 * Logic to report transferred record
	 *
	 * @access public
	 * @return void;
	 * @since 1.0
	 */
	function transferredRecord() {

		global $mainframe;

		//Check for request forgeries
		JRequest::checkToken() or jexit('Invalid Token');

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$gid		= $user->gid;

		if($gid < 25) {
			$canView		= Ownservice::checkAccess('report', 'view', 'report', 'all');
			if ( !$canView ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('report', 'html');

		// Get/Create the model
		$model = & $this->getModel('Report');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('transferredrecord');

		// Display the view
		$view->display();
	}
	
	/**
	 * Logic to report transferred of user
	 *
	 * @access public
	 * @return void;
	 * @since 1.0
	 */
	function user() {

		global $mainframe;

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$gid		= $user->gid;

		if($gid < 25) {
			$canView		= Ownservice::checkAccess('report', 'view', 'report', 'all');
			if ( !$canView ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('report', 'html');

		// Get/Create the model
		$model = & $this->getModel('Report');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('user');

		// Display the view
		$view->display();
	}

	/**
	 * Logic to report transferred user
	 *
	 * @access public
	 * @return void;
	 * @since 1.0
	 */
	function transferredUser() {

		global $mainframe;

		//Check for request forgeries
		JRequest::checkToken() or jexit('Invalid Token');

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$gid		= $user->gid;

		if($gid < 25) {
			$canView		= Ownservice::checkAccess('report', 'view', 'report', 'all');
			if ( !$canView ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('report', 'html');

		// Get/Create the model
		$model = & $this->getModel('Report');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('transferreduser');

		// Display the view
		$view->display();
	}

	/**
	 * Logic to report transfer of staff transfer
	 *
	 * @access public
	 * @return void;
	 * @since 1.0
	 */
	function stafftransfer() {

		global $mainframe;

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$gid		= $user->gid;

		if($gid < 25) {
			$canView		= Ownservice::checkAccess('report', 'view', 'report', 'all');
			if ( !$canView ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('report', 'html');

		// Get/Create the model
		$model = & $this->getModel('Report');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('stafftransfer');

		// Display the view
		$view->display();
	}


	/**
	 * Logic to report transferred staff transfer
	 *
	 * @access public
	 * @return void;
	 * @since 1.0
	 */
	function transferredStaffTransfer() {

		global $mainframe;

		//Check for request forgeries
		JRequest::checkToken() or jexit('Invalid Token');

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$gid		= $user->gid;

		if($gid < 25) {
			$canView		= Ownservice::checkAccess('report', 'view', 'report', 'all');
			if ( !$canView ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		// Create the view
		$view = & $this->getView('report', 'html');

		// Get/Create the model
		$model = & $this->getModel('Report');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('transferredstafftransfer');

		// Display the view
		$view->display();
		
	}

	/**
	 * Download logic transferred
	 *
	 * @access public
	 * @since 1.0
	 */
	function download() {

		global $mainframe;

		//Check for request forgeries
		JRequest::checkToken() or jexit('Invalid Token');

		// Initialise variables
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$gid		= $user->gid;

		if($gid < 25) {
			$canDownload	= Ownservice::checkAccess('report', 'download', 'report', 'all');
			if ( !$canDownload ) {
				//JError::raiseError( 403, JText::_("ALERTNOTAUTH") );
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//Get data form the model
		$model	= $this->getModel('Report');
		$rows	= $model->getTransferred();
		
		require_once(JPATH_COMPONENT_SITE.DS.'classes'.DS.'PHPExcel.php');

		// Create new PHPExcel object
		$objPHPExcel = new PHPExcel();
		
		// Set properties
		$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")
							 ->setLastModifiedBy("Maarten Balliauw")
							 ->setTitle("Office 2007 XLSX Test Document")
							 ->setSubject("Office 2007 XLSX Test Document")
							 ->setDescription("Test document for Office 2007 XLSX, generated using PHP classes.")
							 ->setKeywords("office 2007 openxml php")
							 ->setCategory("Test result file");

		//Set default font
		$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setName('Arial');
		$objPHPExcel->getActiveSheet()->getDefaultStyle()->getFont()->setSize(8);

		// Set column widths
		$objPHPExcel->getActiveSheet()->getColumnDimension('A')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('B')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('C')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('D')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('E')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('F')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('G')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('H')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('I')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('J')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('K')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('L')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('M')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('N')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('O')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('U')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setWidth(22.57);
		$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('Z')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AA')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AB')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AC')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AD')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AE')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AF')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AG')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AH')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AI')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AJ')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AK')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AL')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AM')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AN')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AO')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AP')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AQ')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AR')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AS')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AT')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AU')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AV')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AW')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AX')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AY')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AZ')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BA')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BB')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BC')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BD')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BE')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BF')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BG')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BH')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BI')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BJ')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BK')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BL')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BM')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BN')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BO')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BP')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BQ')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BR')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BS')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BT')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BU')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BV')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BW')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BX')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BY')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BZ')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CA')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CB')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CC')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CD')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CE')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CF')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CG')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CH')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CI')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CJ')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CK')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CL')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CM')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CN')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CO')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CP')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CQ')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CR')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CS')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CT')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CU')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CV')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CW')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CX')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CY')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CZ')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DA')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DB')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DC')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DD')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DE')->setWidth(30);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DF')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DG')->setWidth(15);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DH')->setWidth(15);

		// Set row height
		$objPHPExcel->getActiveSheet()->getRowDimension(1)->setRowHeight(30);
		$objPHPExcel->getActiveSheet()->getRowDimension(2)->setRowHeight(50);

		// Add some data
		$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A1', 'Transaction details')
            ->setCellValue('H1', 'Ordering customer')
            ->setCellValue('K1', 'Ordering customer contact details')
			->setCellValue('W1', 'Ordering customer business details')
            ->setCellValue('AB1', 'Ordering customer identification details')
			->setCellValue('AK1', 'Beneficiary customer')
			->setCellValue('AN1', 'Beneficiary customer contact details')
			->setCellValue('AZ1', 'Beneficiary customer business details')
			->setCellValue('BC1', 'Beneficiary customer account details')
			->setCellValue('BG1', 'Person/organisation accepting the transfer instruction from the ordering customer')
			->setCellValue('BO1', 'Person/organisation accepting the money or property from the ordering customer (if different)')
			->setCellValue('BT1', 'Person/organisation sending the transfer instruction (if different)')
			->setCellValue('CJ1', 'Person/organisation receiving the transfer instruction')
			->setCellValue('CR1', 'Person/organisation distributing money or property (if different)')
			->setCellValue('CX1', 'Retail outlet/business location where money or property is being distributed (if different)')
			->setCellValue('DD1', 'Reason')
			->setCellValue('DE1', 'Person completing this report');


		$objPHPExcel->setActiveSheetIndex(0)
            ->setCellValue('A2', 'Date money/property received from the ordering customer')
			->setCellValue('B2', 'Date money/property made available to the beneficiary customer')
			->setCellValue('C2', 'Currency code')
			->setCellValue('D2', 'Total amount/value')
			->setCellValue('E2', 'Type of transfer')
			->setCellValue('F2', 'Description of property')
			->setCellValue('G2', 'Transaction reference number')
			->setCellValue('H2', 'Full name')
			->setCellValue('I2', 'If known by any other name')
			->setCellValue('J2', 'Date of birth (if an individual)')
			->setCellValue('K2', 'Business/residential address (not a post box address)')
			->setCellValue('L2', 'City/town/suburb')
			->setCellValue('M2', 'State')
			->setCellValue('N2', 'Postcode')
			->setCellValue('O2', 'Country')
			->setCellValue('P2', 'Postal address')
			->setCellValue('Q2', 'City/town/suburb')
			->setCellValue('R2', 'State')
			->setCellValue('S2', 'Postcode')
			->setCellValue('T2', 'Country')
			->setCellValue('U2', 'Phone')
			->setCellValue('V2', 'Email')
			->setCellValue('W2', 'Occupation, business or principal activity')
			->setCellValue('X2', 'ABN, ACN or ARBN')
			->setCellValue('Y2', 'Customer number (allocated by remitter)')
			->setCellValue('Z2', 'Account number (held by remitter)')
			->setCellValue('AA2', 'Business structure (if not an individual)')
			->setCellValue('AB2', 'ID type (1)')
			->setCellValue('AC2', 'ID type (if \'Other\')')
			->setCellValue('AD2', 'Number')
			->setCellValue('AE2', 'Issuer')
			->setCellValue('AF2', 'ID type (2)')
			->setCellValue('AG2', 'ID type (if \'Other\')')
			->setCellValue('AH2', 'Number')
			->setCellValue('AI2', 'Issuer')
			->setCellValue('AJ2', 'Electronic data source')
			->setCellValue('AK2', 'Full name')
			->setCellValue('AL2', 'Date of birth (if an individual)')
			->setCellValue('AM2', 'Any business name under which the beneficiary customer is operating')
			->setCellValue('AN2', 'Business/residential address (not a post box address)')
			->setCellValue('AO2', 'City/town/suburb')
			->setCellValue('AP2', 'State')
			->setCellValue('AQ2', 'Postcode')
			->setCellValue('AR2', 'Country')
			->setCellValue('AS2', 'Postal address')
			->setCellValue('AT2', 'City/town/suburb')
			->setCellValue('AU2', 'State')
			->setCellValue('AV2', 'Postcode')
			->setCellValue('AW2', 'Country')
			->setCellValue('AX2', 'Phone')
			->setCellValue('AY2', 'Email')
			->setCellValue('AZ2', 'Occupation, business or principal activity')
			->setCellValue('BA2', 'ABN, ACN or ARBN')
			->setCellValue('BB2', 'Business structure (if not an individual)')
			->setCellValue('BC2', 'Account number')
			->setCellValue('BD2', 'Name of institution (where account is held)')
			->setCellValue('BE2', 'City')
			->setCellValue('BF2', 'Country')
			->setCellValue('BG2', 'Identification number of the retail outlet/business location')
			->setCellValue('BH2', 'Full name')
			->setCellValue('BI2', 'Business/residential address (not a post box address)')
			->setCellValue('BJ2', 'City/town/suburb')
			->setCellValue('BK2', 'State')
			->setCellValue('BL2', 'Postcode')
			->setCellValue('BM2', 'Is this person/organisation accepting the money or property?')
			->setCellValue('BN2', 'Is this person/organisation sending the transfer instruction?')
			->setCellValue('BO2', 'Full name')
			->setCellValue('BP2', 'Business/residential address (not a post box address)')
			->setCellValue('BQ2', 'City/town/suburb')
			->setCellValue('BR2', 'State')
			->setCellValue('BS2', 'Postcode')
			->setCellValue('BT2', 'Full name')
			->setCellValue('BU2', 'If known by any other name')
			->setCellValue('BV2', 'Date of birth (if an individual)')
			->setCellValue('BW2', 'Business/residential address (not a post box address)')
			->setCellValue('BX2', 'City/town/suburb')
			->setCellValue('BY2', 'State')
			->setCellValue('BZ2', 'Postcode')
			->setCellValue('CA2', 'Postal address')
			->setCellValue('CB2', 'City/town/suburb')
			->setCellValue('CC2', 'State')
			->setCellValue('CD2', 'Postcode')
			->setCellValue('CE2', 'Phone')
			->setCellValue('CF2', 'Email')
			->setCellValue('CG2', 'Occupation, business or principal activity')
			->setCellValue('CH2', 'ABN, ACN or ARBN')
			->setCellValue('CI2', 'Business structure (if not an individual)')
			->setCellValue('CJ2', 'Full name')
			->setCellValue('CK2', 'Business/residential address (not a post box address)')
			->setCellValue('CL2', 'City/town/suburb')
			->setCellValue('CM2', 'State')
			->setCellValue('CN2', 'Postcode')
			->setCellValue('CO2', 'Country')
			->setCellValue('CP2', 'Is this person/organisation distributing money or property?')
			->setCellValue('CQ2', 'Is there a separate retail outlet/business location at which the money or property is being distributed?')
			->setCellValue('CR2', 'Full name')
			->setCellValue('CS2', 'Business/residential address (not a post box address)')
			->setCellValue('CT2', 'City/town/suburb')
			->setCellValue('CU2', 'State')
			->setCellValue('CV2', 'Postcode')
			->setCellValue('CW2', 'Country')
			->setCellValue('CX2', 'Full name')
			->setCellValue('CY2', 'Business/residential address (not a post box address)')
			->setCellValue('CZ2', 'City/town/suburb')
			->setCellValue('DA2', 'State')
			->setCellValue('DB2', 'Postcode')
			->setCellValue('DC2', 'Country')
			->setCellValue('DD2', 'Reason for the transfer')
			->setCellValue('DE2', 'Full name')
			->setCellValue('DF2', 'Job title')
			->setCellValue('DG2', 'Phone')
			->setCellValue('DH2', 'Email');

		if( count($rows) >= 1 ) {
			$i = 3;
			foreach($rows as $row) {

				$objPHPExcel->getActiveSheet()->getStyle('D')->getNumberFormat()->setFormatCode('#,##0.00');
				$objPHPExcel->getActiveSheet()->getStyle('N'.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
				$objPHPExcel->getActiveSheet()->getStyle('U'.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
				$objPHPExcel->getActiveSheet()->getStyle('AQ'.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
				$objPHPExcel->getActiveSheet()->getStyle('BC'.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );
				$objPHPExcel->getActiveSheet()->getStyle('CN'.$i)->getNumberFormat()->setFormatCode( PHPExcel_Style_NumberFormat::FORMAT_TEXT );

				list($da,$ma,$ya) = explode('/',JHTML::_('date', $row->created, '%d/%B/%Y'));
				list($dj,$mj,$yj) =explode('/',JHTML::_('date', $row->birthday, '%d/%B/%Y'));
				$objPHPExcel->setActiveSheetIndex(0)
					/*->setCellValue('A'.$i, date('d/m/Y', strtotime($row->created)))
					->setCellValue('B'.$i,  date('d/m/Y', strtotime($row->created)))*/
					->setCellValue('A'.$i, $da.'/'.JText::_(strtoupper($ma.'_short')).'/'.$ya)
					->setCellValue('B'.$i, $da.'/'.JText::_(strtoupper($ma.'_short')).'/'.$ya)
					->setCellValue('C'.$i, 'AUD')
					->setCellValue('D'.$i, $row->amount)
					->setCellValue('E'.$i, 'Money')
					->setCellValue('F'.$i, 'Money')
					->setCellValue('G'.$i,  $row->invoice)
					->setCellValue('H'.$i, $row->name)
					->setCellValue('I'.$i, '')
					/*->setCellValue('J'.$i,  date('d/m/Y', strtotime($row->birthday)))*/
					->setCellValue('J'.$i, $dj.'/'.JText::_(strtoupper($mj.'_short')).'/'.$yj)
					->setCellValue('K'.$i, trim($row->p_address))
					->setCellValue('L'.$i, $row->p_city)
					->setCellValue('M'.$i, $row->p_state)
					->setCellValue('O'.$i, $row->p_country)
					->setCellValue('P'.$i, '')
					->setCellValue('Q'.$i, '')
					->setCellValue('R'.$i, '')
					->setCellValue('S'.$i, '')
					->setCellValue('T'.$i, '')
					->setCellValue('V'.$i, '')
					->setCellValue('W'.$i, '')
					->setCellValue('X'.$i, '')
					->setCellValue('Y'.$i, '')
					->setCellValue('Z'.$i, '')
					->setCellValue('AA'.$i, '')
					->setCellValue('AB'.$i, $row->p_id_type)
					->setCellValue('AC'.$i, '')
					->setCellValue('AD'.$i, $row->p_id_number)
					->setCellValue('AE'.$i, (strtolower($row->p_issuer)=='other'?$row->issuer_other:$row->p_issuer))
					->setCellValue('AF'.$i, '')
					->setCellValue('AG'.$i, '')
					->setCellValue('AH'.$i, '')
					->setCellValue('AI'.$i, '')
					->setCellValue('AJ'.$i, '')
					->setCellValue('AK'.$i, $row->account_name)
					->setCellValue('AL'.$i, '')
					->setCellValue('AM'.$i, '')
					->setCellValue('AN'.$i, trim($row->a_address))
					->setCellValue('AO'.$i, $row->a_city)
					->setCellValue('AP'.$i, $row->a_state)
					->setCellValue('AR'.$i, $row->a_country)
					->setCellValue('AS'.$i, '')
					->setCellValue('AT'.$i, '')
					->setCellValue('AU'.$i, '')
					->setCellValue('AV'.$i, '')
					->setCellValue('AW'.$i, '')
					->setCellValue('AY'.$i, $row->a_email)
					->setCellValue('AZ'.$i, '')
					->setCellValue('BA'.$i, '')
					->setCellValue('BB'.$i, '')
					->setCellValue('BD'.$i, ($row->bank_name=='other'?$row->bank_other:$row->bank_name))
					->setCellValue('BE'.$i, $row->branch_city)
					->setCellValue('BF'.$i, $row->a_country)
					->setCellValue('BG'.$i, '2')
					->setCellValue('BH'.$i, $row->branchname)
					->setCellValue('BI'.$i, $row->b_address)
					->setCellValue('BJ'.$i, $row->b_city)
					->setCellValue('BK'.$i, $row->b_state)
					->setCellValue('BL'.$i, $row->b_postcode)
					->setCellValue('BM'.$i, 'Yes')
					->setCellValue('BN'.$i, 'Yes')
					->setCellValue('BO'.$i, '')
					->setCellValue('BP'.$i, '')
					->setCellValue('BQ'.$i, '')
					->setCellValue('BR'.$i, '')
					->setCellValue('BS'.$i, '')
					->setCellValue('BT'.$i, '')
					->setCellValue('BU'.$i, '')
					->setCellValue('BV'.$i, '')
					->setCellValue('BW'.$i, '')
					->setCellValue('BX'.$i, '')
					->setCellValue('BY'.$i, '')
					->setCellValue('BZ'.$i, '')
					->setCellValue('CA'.$i, '')
					->setCellValue('CB'.$i, '')
					->setCellValue('CC'.$i, '')
					->setCellValue('CD'.$i, '')
					->setCellValue('CE'.$i, '')
					->setCellValue('CF'.$i, '')
					->setCellValue('CG'.$i, '')
					->setCellValue('CH'.$i, '')
					->setCellValue('CI'.$i, '')
					->setCellValue('CJ'.$i, $row->firstname.' '.$row->lastname)
					->setCellValue('CK'.$i, $row->recei_address)
					->setCellValue('CL'.$i, $row->recei_city)
					->setCellValue('CM'.$i, $row->recei_state)
					->setCellValue('CO'.$i, $row->recei_country)
					->setCellValue('CP'.$i, 'Yes')
					->setCellValue('CQ'.$i, 'No')
					->setCellValue('CR'.$i, '')
					->setCellValue('CS'.$i, '')
					->setCellValue('CT'.$i, '')
					->setCellValue('CU'.$i, '')
					->setCellValue('CV'.$i, '')
					->setCellValue('CW'.$i, '')
					->setCellValue('CX'.$i, '')
					->setCellValue('CY'.$i, '')
					->setCellValue('CZ'.$i, '')
					->setCellValue('DA'.$i, '')
					->setCellValue('DB'.$i, '')
					->setCellValue('DC'.$i, '')
					->setCellValue('DD'.$i, '')
					->setCellValue('DE'.$i, '')
					->setCellValue('DF'.$i, '')
					->setCellValue('DG'.$i, '')
					->setCellValue('DH'.$i, '');
			
				$objPHPExcel->getActiveSheet()->getCell('N'.$i)->setValueExplicit($row->p_postcode, PHPExcel_Cell_DataType::TYPE_STRING);
				$objPHPExcel->getActiveSheet()->getCell('U'.$i)->setValueExplicit($row->p_phone, PHPExcel_Cell_DataType::TYPE_STRING);
				$objPHPExcel->getActiveSheet()->getCell('AQ'.$i)->setValueExplicit($row->a_postcode, PHPExcel_Cell_DataType::TYPE_STRING);
				$objPHPExcel->getActiveSheet()->getCell('AX'.$i)->setValueExplicit($row->a_phone, PHPExcel_Cell_DataType::TYPE_STRING);
				$objPHPExcel->getActiveSheet()->getCell('BC'.$i)->setValueExplicit($row->account, PHPExcel_Cell_DataType::TYPE_STRING);
				$objPHPExcel->getActiveSheet()->getCell('CN'.$i)->setValueExplicit($row->recei_postcode, PHPExcel_Cell_DataType::TYPE_STRING);

				$objPHPExcel->getActiveSheet()->getStyle('AD'.$i)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_TEXT);

				$i++;
			}
		}

		$objPHPExcel->getActiveSheet()->mergeCells('A1:G1');
		$objPHPExcel->getActiveSheet()->mergeCells('H1:J1');
		$objPHPExcel->getActiveSheet()->mergeCells('K1:V1');
		$objPHPExcel->getActiveSheet()->mergeCells('W1:AA1');
		$objPHPExcel->getActiveSheet()->mergeCells('AB1:AJ1');
		$objPHPExcel->getActiveSheet()->mergeCells('AK1:AM1');
		$objPHPExcel->getActiveSheet()->mergeCells('AN1:AY1');
		$objPHPExcel->getActiveSheet()->mergeCells('AZ1:BB1');
		$objPHPExcel->getActiveSheet()->mergeCells('BC1:BF1');
		$objPHPExcel->getActiveSheet()->mergeCells('BG1:BN1');
		$objPHPExcel->getActiveSheet()->mergeCells('BO1:BS1');
		$objPHPExcel->getActiveSheet()->mergeCells('BT1:CI1');
		$objPHPExcel->getActiveSheet()->mergeCells('CJ1:CQ1');
		$objPHPExcel->getActiveSheet()->mergeCells('CR1:CW1');
		$objPHPExcel->getActiveSheet()->mergeCells('CX1:DC1');
		$objPHPExcel->getActiveSheet()->mergeCells('DE1:DH1');

		// Hide "Phone" and "fax" column
		/*$objPHPExcel->getActiveSheet()->getColumnDimension('P')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('Q')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('R')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('S')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('T')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('V')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('W')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('X')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('Y')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('Z')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AA')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AC')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AF')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AG')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AH')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AI')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AJ')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AL')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AM')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AS')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AT')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AU')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AV')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AW')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('AZ')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BA')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BB')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BG')->setVisible(false);

		$objPHPExcel->getActiveSheet()->getColumnDimension('BO')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BP')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BQ')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BR')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BS')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BT')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BU')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BV')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BW')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BX')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BY')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('BZ')->setVisible(false);

		$objPHPExcel->getActiveSheet()->getColumnDimension('CA')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CB')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CC')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CD')->setVisible(false);

		$objPHPExcel->getActiveSheet()->getColumnDimension('CE')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CF')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CG')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CH')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CI')->setVisible(false);

		$objPHPExcel->getActiveSheet()->getColumnDimension('CR')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CS')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CT')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CU')->setVisible(false);

		$objPHPExcel->getActiveSheet()->getColumnDimension('CV')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CW')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CX')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CY')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('CZ')->setVisible(false);

		$objPHPExcel->getActiveSheet()->getColumnDimension('DA')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DB')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DC')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DD')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DE')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DF')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DG')->setVisible(false);
		$objPHPExcel->getActiveSheet()->getColumnDimension('DH')->setVisible(false);*/

		// Freeze panes
		$objPHPExcel->getActiveSheet()->freezePane('A3');

		// Set style on cell
		$objPHPExcel->getActiveSheet()->getStyle('A1:DH1')->applyFromArray(
			array(
				'alignment' => array(
				'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
				'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
				)
			)
		);
		$objPHPExcel->getActiveSheet()->getStyle('A2:DH2')->applyFromArray(
			array(
				'alignment' => array(
				'horizontal' => PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
				'vertical' => PHPExcel_Style_Alignment::VERTICAL_CENTER,
				'wrap'=>true,
				)
			)
		);

		// Rename sheet
		$objPHPExcel->getActiveSheet()->setTitle('IFTI-DRA OUT');

		// Set active sheet index to the first sheet, so Excel opens this as the first sheet
		$objPHPExcel->setActiveSheetIndex(0);

		// Redirect output to a client�s web browser (Excel2007)
		/*header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
		header('Content-Disposition: attachment;filename="'.date('d-m-Y').'IFTI-DRA OUT.xlsx"');
		header('Cache-Control: max-age=0');

		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
		$objWriter->save('php://output');*/
		header('Content-Type: application/vnd.ms-excel');
		header('Content-Disposition: attachment;filename="'.date('d-m-Y').'IFTI-DRA OUT.xls"');
		header('Cache-Control: max-age=0');
		
		$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
		$objWriter->save('php://output');
		exit;
	}

	/**
	 * Method to get Member
	 * 
	 * @return string
	 * @since 1.0
	 */
	 function viewmembers()
	 {
	 	// Check for request forgeries
		JRequest::checkToken('request') or jexit( 'Invalid Token' );

		$user =&JFactory::getUser();

		//header('Content-type: application/json');
		@ob_end_clean();
		header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
		header("Cache-Control: no-cache");
		header("Pragma: no-cache");
		//header("Content-type:text/json");

		$model 			=  $this->getModel('Report');
		$memberobjs 	=  $model->getmembers(JRequest::getVar('q'));
		
		$array = array();
		
		echo "[";
		foreach($memberobjs as $member) {
			$array[] = "{\"id\":\"".$member->id."\",\"name\":\"".$member->username.' '.$member->name."\"}";
		}
		echo implode(",", $array);
		echo "]";
		exit();
	 }

	 /**
	 * Logic to delete transaction
	 *
	 * @access public
	 * @return void
	 * @since 1.0
	*/
	function delete() {

		global $mainframe;

		//Check for request forgeries
		JRequest::checkToken() or jexit('Invalid Token');

		//Initialise variables
		$user		 = & JFactory::getUser();

		$cid		= JRequest::getVar( 'cid', 0, 'post', 'array' );
		
		$model 		= $this->getModel('Report');

		if($user->gid < 25) {
			$canDelete		= Ownservice::checkAccess('transaction', 'delete', 'transaction', 'all');

			if ( !$canDelete ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		if (!is_array( $cid ) || count( $cid ) < 1)  {
			$msg = '';
			JError::raiseWarning(500, JText::_( 'OWNSERVICE_SELECT_ITEM_DELETED' ) );

		} else {

			if (!$model->delete($cid)) {
				JError::raiseError(500, JText::_( 'OWNSERVICE_TRANSACTION_FAILED' ));
			}
			
			$mainframe->enqueueMessage(JText::_( 'OWNSERVICE_TRANSACTION_DELETED' ));
		}
		
		// Create the view
		$view = & $this->getView('report', 'html');

		// Push the model into the view (as default)
		$view->setModel($model, true);

		// Set the layout
		$view->setLayout('transferredrecord');

		// Display the view
		$view->display();
	}
}
